This notebook is one in a series of many, where we explore how different data analysis strategies affect the outcome of a proteomics experiment based on isobaric labeling and mass spectrometry. Each analysis strategy or ‘workflow’ can be divided up into different components; it is recommend you read more about that in the introduction notebook.
In this notebook specifically, we investigate the effect of varying the Differential Expression testing component on the outcome of the differential expression results. The four component variants are: moderated t-test, Wilcoxon test, permutation test, and Reproducibility-Optimized Test Statistic (ROTS).
The R packages and helper scripts necessary to run this notebook are listed in the next code chunk: click the ‘Code’ button. Each code section can be expanded in a similar fashion. You can also download the entire notebook source code.
library(stringi)
library(gridExtra)
library(dendextend)
library(kableExtra)
library(limma)
library(psych)
library(tidyverse)
library(matrixTests)
library(coin)
library(ROTS)
source('other_functions.R')
source('plotting_functions.R')
Let’s load our PSM-level data set:
data.list <- readRDS(params$input_data_p)
dat.l <- data.list$dat.l # data in long format
display_dataframe_head(dat.l)
| Mixture | TechRepMixture | Condition | BioReplicate | Run | Channel | Protein | Peptide | RT | Charge | PTM | intensity | TotalIntensity | Ions.Score | DeltaMZ | isoInterOk | noNAs | onehit.protein | shared.peptide |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Mixture2 | 1 | 1 | Mixture2_1 | Mixture2_1 | 127C | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 44048.41 | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE |
| Mixture2 | 1 | 0.5 | Mixture2_0.5 | Mixture2_1 | 127N | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 38298.89 | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE |
| Mixture2 | 1 | 0.125 | Mixture2_0.125 | Mixture2_1 | 128C | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 39552.81 | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE |
| Mixture2 | 1 | 0.667 | Mixture2_0.667 | Mixture2_1 | 128N | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 56730.70 | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE |
| Mixture2 | 1 | 0.667 | Mixture2_0.667 | Mixture2_1 | 129C | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 48744.49 | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE |
| Mixture2 | 1 | 1 | Mixture2_1 | Mixture2_1 | 129N | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 60179.96 | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE |
After the filtering done in data_prep.R, there are 19 UPS1 proteins remaining, even though 48 were originally spiked in.
# which proteins were spiked in?
spiked.proteins <- dat.l %>% distinct(Protein) %>% filter(stri_detect(Protein, fixed='ups')) %>% pull %>% as.character
remove_factors(spiked.proteins)
## [1] "P02787ups" "P02788ups" "P01133ups" "P69905ups" "P01008ups" "P02741ups" "P01375ups" "P10636-8ups" "O00762ups"
## [10] "P62988ups" "P10145ups" "P05413ups" "P00915ups" "P02753ups" "P02144ups" "P01344ups" "P01579ups" "P00709ups"
## [19] "P01127ups"
tmp=dat.l %>% distinct(Protein) %>% pull %>% as.character
# protein subsampling
if (params$subsample_p>0 & params$subsample_p==floor(params$subsample_p) & params$subsample_p<=length(tmp)){
sub.prot <- tmp[sample(1:length(tmp), size=params$subsample_p)]
if (length(spiked.proteins)>0) sub.prot <- c(sub.prot,spiked.proteins)
dat.l <- dat.l %>% filter(Protein %in% sub.prot)
}
Before we begin, let’s set an RNG seed for the permutation testing, store the metadata in sample.info and show some entries below. We also pick technical replicates with a dilution factor of 0.5 as the reference condition of interest. Each condition is represented by two of eight reporter Channels in each Run.
## [1] 9107
display_dataframe_head(sample.info)
| Run | Run.short | Channel | Sample | Sample.short | Condition | Color |
|---|---|---|---|---|---|---|
| Mixture1_1 | Mix1_1 | 127C | Mixture1_1:127C | Mix1_1:127C | 0.125 | black |
| Mixture1_1 | Mix1_1 | 127N | Mixture1_1:127N | Mix1_1:127N | 0.667 | green |
| Mixture1_1 | Mix1_1 | 128C | Mixture1_1:128C | Mix1_1:128C | 1 | red |
| Mixture1_1 | Mix1_1 | 128N | Mixture1_1:128N | Mix1_1:128N | 0.5 | blue |
| Mixture1_1 | Mix1_1 | 129C | Mixture1_1:129C | Mix1_1:129C | 0.5 | blue |
| Mixture1_1 | Mix1_1 | 129N | Mixture1_1:129N | Mix1_1:129N | 0.125 | black |
referenceCondition
## [1] "0.5"
channelNames
## [1] "127C" "127N" "128C" "128N" "129C" "129N" "130C" "130N"
We use the default unit scale: the log2-transformed reportion ion intensities.
dat.unit.l <- dat.l %>% mutate(response=log2(intensity)) %>% select(-intensity)
display_dataframe_head(dat.unit.l)
| Mixture | TechRepMixture | Condition | BioReplicate | Run | Channel | Protein | Peptide | RT | Charge | PTM | TotalIntensity | Ions.Score | DeltaMZ | isoInterOk | noNAs | onehit.protein | shared.peptide | response |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Mixture2 | 1 | 1 | Mixture2_1 | Mixture2_1 | 127C | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE | 15.42680 |
| Mixture2 | 1 | 0.5 | Mixture2_0.5 | Mixture2_1 | 127N | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE | 15.22502 |
| Mixture2 | 1 | 0.125 | Mixture2_0.125 | Mixture2_1 | 128C | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE | 15.27149 |
| Mixture2 | 1 | 0.667 | Mixture2_0.667 | Mixture2_1 | 128N | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE | 15.79184 |
| Mixture2 | 1 | 0.667 | Mixture2_0.667 | Mixture2_1 | 129C | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE | 15.57295 |
| Mixture2 | 1 | 1 | Mixture2_1 | Mixture2_1 | 129N | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 394657.6 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE | 15.87700 |
Median sweeping means subtracting from each PSM quantification value the spectrum median (i.e., the row median computed across samples/channels) and the sample median (i.e., the column median computed across features). If the unit scale is set to intensities or ratios, the multiplicative variant of this procedure is applied: subtraction is replaced by division.
Since median sweeping needs to be applied on matrix-like data, let’s switch to wide format. (Actually, this is semi-wide, since the Channel columns still have contributions form all Runs, but that’s OK because in the next step we split by Run.)
# switch to wide format
dat.unit.w <- pivot_wider(data = dat.unit.l, id_cols=-one_of(c('Condition', 'BioReplicate')), names_from=Channel, values_from=response)
display_dataframe_head(dat.unit.w)
| Mixture | TechRepMixture | Run | Protein | Peptide | RT | Charge | PTM | TotalIntensity | Ions.Score | DeltaMZ | isoInterOk | noNAs | onehit.protein | shared.peptide | 127C | 127N | 128C | 128N | 129C | 129N | 130C | 130N |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Mixture2 | 1 | Mixture2_1 | P21291 | [K].gFGFGQGAGALVHSE.[-] | 144.9444 | 2 | N-Term(TMT6plex) | 394657.56 | 65 | 0.00052 | TRUE | TRUE | FALSE | FALSE | 15.42680 | 15.22502 | 15.27149 | 15.79184 | 15.57295 | 15.87700 | 15.71883 | 15.69836 |
| Mixture2 | 1 | Mixture2_1 | P30511 | [K].wAAVVVPPGEEQR.[Y] | 137.1704 | 2 | N-Term(TMT6plex) | 180359.11 | 27 | -0.00653 | TRUE | TRUE | TRUE | FALSE | 14.36513 | 14.14964 | 14.27690 | 14.65920 | 14.44955 | 14.58652 | 14.54510 | 14.57900 |
| Mixture2 | 1 | Mixture2_1 | P02787ups | [K].sASDLTWDNLk.[G] | 148.8299 | 3 | N-Term(TMT6plex); K11(TMT6plex) | 507218.12 | 35 | -0.00005 | TRUE | TRUE | FALSE | FALSE | 16.31046 | 15.32833 | 15.11530 | 16.27180 | 15.92615 | 16.73355 | 15.74796 | 15.42268 |
| Mixture2 | 1 | Mixture2_1 | Q9UBQ5 | [K].iDFDSVSSIMASSQ.[-] | 201.8727 | 2 | N-Term(TMT6plex) | 120944.32 | 72 | 0.00119 | TRUE | TRUE | FALSE | FALSE | 13.51956 | 13.51995 | 13.66172 | 14.36018 | 13.87050 | 14.20738 | 13.86685 | 13.83673 |
| Mixture2 | 1 | Mixture2_1 | Q5H9R7 | [R].tGQPSAPGDTSVNGPV.[-] | 106.9002 | 2 | N-Term(TMT6plex) | 99098.46 | 23 | -0.00133 | TRUE | TRUE | FALSE | FALSE | 13.54513 | 13.17495 | 13.34133 | 13.81323 | 13.58510 | 14.02262 | 13.60511 | 13.51803 |
| Mixture2 | 1 | Mixture2_1 | P43490 | [K].nAQLNIELEAAHH.[-] | 99.8437 | 3 | N-Term(TMT6plex) | 497023.17 | 15 | 0.00061 | TRUE | TRUE | FALSE | FALSE | 15.58965 | 15.43193 | 15.86127 | 16.18651 | 15.86677 | 16.28384 | 15.93733 | 16.03418 |
dat.norm.w <- emptyList(variant.names)
Median sweeping means subtracting from each PSM quantification value the spectrum median (i.e., the row median computed across samples/channels) and the sample median (i.e., the column median computed across features). If the unit scale is set to intensities or ratios, the multiplicative variant of this procedure is applied: subtraction is replaced by division. First, let’s sweep the medians of all the rows, and do the columns later as suggested by [Herbrich at al.](https://doi.org/10.1021/pr300624g. No need to split this per Run, because each row in this semi-wide format contains only values from one Run and each median calculation is independent of the other rows.
# subtract the spectrum median log2intensity from the observed log2intensities
dat.norm.w <- dat.unit.w
dat.norm.w[,channelNames] <- median_sweep(dat.norm.w[,channelNames], 1, '-')
Within each Run and within each Channel, we replace multiple related observations with their median. First, for each Peptide (median of the PSM values), then for each Protein (median of the peptide values).
# normalized data
dat.norm.summ.w <- dat.norm.w %>% group_by(Run, Protein, Peptide) %>% summarise_at(.vars = channelNames, .funs = median) %>% summarise_at(.vars = channelNames, .funs = median) %>% ungroup()
Let’s also summarize the non-normalized data for comparison later on.
# non-normalized data
# group by (run,)protein,peptide then summarize twice (once on each level)
# add select() statement because summarise_at is going bananas over character columns
dat.nonnorm.summ.w <- dat.unit.w %>% group_by(Run, Protein, Peptide) %>% select(Run, Protein, Peptide, channelNames) %>% summarise_at(.vars = channelNames, .funs = median) %>% select(Run, Protein, channelNames) %>% summarise_at(.vars = channelNames, .funs = median) %>% ungroup()
Now that the data is on the protein level, let’s sweep all values separately per protein in the columns/samples. This is slightly different from sweeping before the summarization step because the median of medians is not the same as the grand median, but this does not introduce any bias.
# medianSweeping: in each channel, subtract median computed across all proteins within the channel
# do the above separately for each MS run
x.split <- split(dat.norm.summ.w, dat.norm.summ.w$Run)
x.split.norm <- lapply(x.split, function(y) {
y[,channelNames] <- median_sweep(y[,channelNames], 2, '-')
return(y)
})
dat.norm.summ.w <- bind_rows(x.split.norm)
Before getting to the DEA section, let’s do some basic quality control and take a sneak peek at the differences between the component variants we’ve chosen. First, however, we should make the data completely wide, so that each sample gets it’s own unique column.
# make data completely wide (also across runs)
## normalized data
dat.norm.summ.w2 <- dat.norm.summ.w %>% pivot_wider(names_from = Run, values_from = all_of(channelNames), names_glue = "{Run}:{.value}")
## non-normalized data
dat.nonnorm.summ.w2 <- dat.nonnorm.summ.w %>% pivot_wider(names_from = Run, values_from = all_of(channelNames), names_glue = "{Run}:{.value}")
These boxplots show that the distributions are symmetrical and centered after median sweeping normalization, as desired and expected.
# use (half-)wide format
par(mfrow=c(1,2))
boxplot_w(dat.nonnorm.summ.w,sample.info, 'raw')
boxplot_w(dat.norm.summ.w, sample.info, 'normalized')
We then make MA plots of two single samples taken from condition 0.5 and condition 0.125, measured in different MS runs (samples Mixture2_1:127C and Mixture1_2:129N, respectively). Clearly, the normalization had a strong variance-reducing effect on the fold changes.
# use wide2 format
p1 <- maplot_ils(dat.nonnorm.summ.w2, ma.onesample.num, ma.onesample.denom, scale='log', 'raw', spiked.proteins)
p2 <- maplot_ils(dat.norm.summ.w2, ma.onesample.num, ma.onesample.denom, scale='log', 'normalized', spiked.proteins)
grid.arrange(p1, p2, ncol=2)
To increase the robustness of these results, let’s make some more MA plots, but now for all samples from condition 0.5 and condition 0.125 (quantification values averaged within condition). Indeed, even the raw, unnormalized data now show less variability. It seems that by using more samples (now 8 in both the enumerator and denominator instead of just one) in the fold change calculation the rolling average is more robust and the Sum summarization data bias has been reduced (but not disappeared).
channels.num <- sample.info %>% filter(Condition==ma.allsamples.num) %>% select(Sample) %>% pull
channels.denom <- sample.info %>% filter(Condition==ma.allsamples.denom) %>% select(Sample) %>% pull
p1 <- maplot_ils(dat.nonnorm.summ.w2, channels.num, channels.denom, scale='log', 'raw', spiked.proteins)
p2 <- maplot_ils(dat.norm.summ.w2, channels.num, channels.denom, scale='log', 'normalized', spiked.proteins)
grid.arrange(p1, p2, ncol=2)
Now, let’s check if these multi-dimensional data contains some kind of grouping; It’s time to make PCA plots. Even though PC1 does seem to capture the conditions, providing a gradient for the dilution number, only the 0.125 condition is completely separable in the normalized data.
par(mfrow=c(1, 2))
pcaplot_ils(dat.nonnorm.summ.w2 %>% select(-'Protein'), info=sample.info, 'raw')
pcaplot_ils(dat.norm.summ.w2 %>% select(-'Protein'), info=sample.info, 'normalized')
There are only 19 proteins supposed to be differentially expressed in this data set, which is only a very small amount in both relative (to the 4083 proteins total) and absolute (for a biological sample) terms.
Therefore, let’s see what the PCA plots look like if we were to only use the spiked proteins in the PCA. Now, the separation between different conditions has become more distinct, which suggests the experiment was carried out successfully: only conditions 0.5 and 0.667 aren’t clearly separable.
par(mfrow=c(1, 2))
pcaplot_ils(dat.nonnorm.summ.w2 %>% filter(Protein %in% spiked.proteins) %>% select(-'Protein'), info=sample.info, 'raw')
pcaplot_ils(dat.norm.summ.w2 %>% filter(Protein %in% spiked.proteins) %>% select(-'Protein'), info=sample.info, 'normalized')
Notice how for all PCA plots, the percentage of variance explained by PC1 is now much greater than when using data from all proteins. In a real situation without spiked proteins, you might plot data corresponding to the top X most differential proteins instead.
The PCA plots of all proteins has a rather lower fraction of variance explained by PC1. We can confirm this using the hierarchical clustering dendrograms below: when considering the entire multidimensional space, the different conditions are not very separable at all. This is not surprising as there is little biological variation between the conditions: there are only 19 truly differential proteins, and they all (ought to) covary in exactly the same manner (i.e., their variation can be captured in one dimension).
par(mfrow=c(1, 2))
dendrogram_ils(dat.nonnorm.summ.w2 %>% select(-Protein), info=sample.info, 'raw')
dendrogram_ils(dat.norm.summ.w2 %>% select(-Protein), info=sample.info, 'normalized')
Our last quality check involves a measure of how well each variant was able to assist in removing the run effect. Below are the distributions of p-values from a linear model for the response variable with Run as a covariate. If the run effect was removed successfully, these p-values ought to be large. Clearly, the raw data contains a run effect, which is partially removed by the normalization.
dat <- list(dat.nonnorm.summ.l,dat.norm.summ.l)
names(dat) <- c('raw','normalized')
run_effect_plot(dat)
We wish to look at the log2 fold changes of each condition w.r.t. the reference condition with dilution ratio 0.125. Since we are working with a log2 unit scale already, this means that for each protein we just look at the difference in mean observation across all channels between one condition and the reference condition. Note that this is not the same as looking at the log2 of the ratio of mean raw intensities for each condition (left hand side below), nor the mean ratio of raw intensities for each condition (right hand side below), since \(log_2 (\frac{mean(B)}{mean(A)}) \neq \frac{mean(log_2 (B))}{mean(log_2 (A))} \neq mean(\frac{log_2 (B)}{log_2 (A)})\).
In the next subsections, we use our four components variants to check whether these fold changes are significant (criterium: \(q<0.05\)). After testing, we make a correction for multiple testing using the Benjamini-Hochberg method in order to keep the FDR under control.
The moderated t-test slightly adapted from the limma package, which in use cases like ours should improve statistical power over a regular t-test. In a nutshell, this is a t-test done independently for each protein, although the variance used in the calculation of the t-statistic is moderated using some empirical Bayes estimation.
# design matrix as used in ANOVA testing.
design.matrix <- get_design_matrix(referenceCondition, sample.info)
dat.dea <- emptyList(variant.names)
this_scale <- scale.vec
d <- column_to_rownames(as.data.frame(dat.norm.summ.w2), 'Protein')
dat.dea$moderated_ttest <- moderated_ttest(dat=d, design.matrix, scale=this_scale)
For each condition, we now get the fold changes, moderated and unmoderated p-values, moderated and unmoderated q-values (BH-adjusted p-values), and some other details: see head of dataframe below.
display_dataframe_head(dat.dea$moderated_ttest)
| logFC_0.125 | logFC_0.667 | logFC_1 | t.ord_0.125 | t.ord_0.667 | t.ord_1 | t.mod_0.125 | t.mod_0.667 | t.mod_1 | p.ord_0.125 | p.ord_0.667 | p.ord_1 | p.mod_0.125 | p.mod_0.667 | p.mod_1 | q.ord_0.125 | q.ord_0.667 | q.ord_1 | q.mod_0.125 | q.mod_0.667 | q.mod_1 | df.r | df.0 | s2.0 | s2 | s2.post | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| A0AVT1 | -0.0296332 | -0.0190075 | 0.0086228 | -1.2236300 | -0.7848676 | 0.3560550 | -1.1698892 | -0.7503969 | 0.3404173 | 0.2312896 | 0.4391218 | 0.7244682 | 0.2512504 | 0.4588575 | 0.7359131 | 0.9569613 | 0.9960123 | 0.9898622 | 0.9350748 | 0.9805978 | 0.9840728 | 28 | 2.018963 | 0.0056242 | 0.0023459 | 0.0025664 |
| A0FGR8 | 0.0121287 | 0.0389655 | 0.0247813 | 0.3627376 | 1.1653597 | 0.7411452 | 0.3596350 | 1.1553923 | 0.7348061 | 0.7195248 | 0.2537054 | 0.4647764 | 0.7216378 | 0.2570437 | 0.4681594 | 0.9841943 | 0.9960123 | 0.9820911 | 0.9795638 | 0.9723943 | 0.9650451 | 28 | 2.018963 | 0.0056242 | 0.0044720 | 0.0045495 |
| A0MZ66 | 0.0035130 | -0.0009938 | -0.0183834 | 0.0761086 | -0.0215311 | -0.3982773 | 0.0769941 | -0.0217816 | -0.4029113 | 0.9398739 | 0.9829747 | 0.6934465 | 0.9391391 | 0.9827663 | 0.6898687 | 0.9978394 | 0.9975071 | 0.9898622 | 0.9964971 | 0.9975410 | 0.9825206 | 28 | 2.018963 | 0.0056242 | 0.0085220 | 0.0083271 |
| A1L0T0 | 0.0520381 | -0.0328378 | -0.0500166 | 0.7951963 | -0.5017969 | -0.7643056 | 0.8165216 | -0.5152539 | -0.7848025 | 0.4358354 | 0.6212896 | 0.4536089 | 0.4229483 | 0.6115101 | 0.4409319 | 0.9569613 | 0.9975071 | 0.9820911 | 0.9350748 | 0.9924981 | 0.9650451 | 20 | 2.018963 | 0.0056242 | 0.0128474 | 0.0121851 |
| A3KMH1 | 0.4342224 | 0.3206653 | 0.5484563 | 1.7510253 | 1.2931002 | 2.2116798 | 1.8344616 | 1.3547163 | 2.3170662 | 0.0952654 | 0.2107143 | 0.0387933 | 0.0801348 | 0.1892462 | 0.0301887 | 0.9569613 | 0.9960123 | 0.7960743 | 0.9350748 | 0.9540539 | 0.7680706 | 20 | 2.018963 | 0.0056242 | 0.1844849 | 0.1680848 |
| A4D1E9 | -0.0219254 | -0.0731552 | -0.0426655 | -0.4771987 | -1.5921945 | -0.9285977 | -0.4796669 | -1.6004298 | -0.9334006 | 0.6383938 | 0.1270236 | 0.3641701 | 0.6361944 | 0.1237544 | 0.3607366 | 0.9741019 | 0.9841938 | 0.9820911 | 0.9644451 | 0.9260254 | 0.9650451 | 20 | 2.018963 | 0.0056242 | 0.0063331 | 0.0062681 |
The Wilcoxon test (Wilcoxon, F.) is a non-parametric rank-based test for comparing two groups (i.e., biological conditions). For each protein separately, the test is applied to each condition w.r.t. the reference condition 0.5.
@Piotr: uncomment the explanation of Wilcoxon fold changes if desired, otherwise explain why not
otherConditions <- dat.l %>% distinct(Condition) %>% pull(Condition) %>% as.character %>% sort
otherConditions <- otherConditions[-match(referenceCondition, otherConditions)]
dat.dea$Wilcoxon <- wilcoxon_test(dat.norm.summ.w2, sample.info, referenceCondition, otherConditions, logFC.method='ratio')
For each condition, we now get fold change estimates, p-values and q-values (adjusted p-values): see head of dataframe below.
display_dataframe_head(dat.dea$Wilcoxon)
| logFC_0.125 | logFC_0.667 | logFC_1 | t.mod_0.125 | t.mod_0.667 | t.mod_1 | p.mod_0.125 | p.mod_0.667 | p.mod_1 | q.mod_0.125 | q.mod_0.667 | q.mod_1 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| A0AVT1 | -0.0294565 | -0.0193514 | 0.0089746 | 21 | 22 | 34 | 0.2786325 | 0.3282051 | 0.8784771 | 0.9900182 | 1 | 1 |
| A0FGR8 | 0.0132333 | 0.0392210 | 0.0259210 | 40 | 45 | 43 | 0.4418026 | 0.1948718 | 0.2786325 | 1.0000000 | 1 | 1 |
| A0MZ66 | -0.0002205 | -0.0040481 | -0.0214527 | 27 | 27 | 25 | 0.6453768 | 0.6453768 | 0.5053613 | 1.0000000 | 1 | 1 |
| A1L0T0 | 0.0501547 | -0.0362998 | -0.0482751 | 23 | 14 | 12 | 0.4848485 | 0.5887446 | 0.3939394 | 1.0000000 | 1 | 1 |
| A3KMH1 | 0.3833735 | 0.2894750 | 0.5205885 | 28 | 23 | 29 | 0.1320346 | 0.4848485 | 0.0930736 | 0.9900182 | 1 | 1 |
| A4D1E9 | -0.0202724 | -0.0716067 | -0.0423592 | 12 | 10 | 11 | 0.3939394 | 0.2402597 | 0.3095238 | 1.0000000 | 1 | 1 |
The Fisher-Pitman permutation test (Pitman, E.J.G.) is a classical non-parametric permutation test based on the difference between group (i.e., biological condition) means. Multiple times, the columns of the quantification matrix are randomly shuffled and the resulting shuffled data set is tested, such that a null distribution of the test statistic is constructed. The final p-values are then computed by comparing the observed test statistic value with the null distribution.
dat.dea$permutation_test <- permutation_test(dat.norm.summ.l, referenceCondition, otherConditions, seed=seed, distribution='exact')
For each condition, we now get fold change estimates, p-values and q-values (adjusted p-values): see head of dataframe below.
display_dataframe_head(dat.dea$permutation_test)
| logFC_0.125 | logFC_0.667 | logFC_1 | p.mod_0.125 | p.mod_0.667 | p.mod_1 | q.mod_0.125 | q.mod_0.667 | q.mod_1 | |
|---|---|---|---|---|---|---|---|---|---|
| A0AVT1 | -0.0296332 | -0.0190075 | 0.0086228 | 0.2505051 | 0.3560995 | 0.7504274 | 0.9744878 | 1.0000000 | 1 |
| A0FGR8 | 0.0121287 | 0.0389655 | 0.0247813 | 0.7123543 | 0.1645688 | 0.4610723 | 0.9927812 | 0.9978006 | 1 |
| A0MZ66 | 0.0035130 | -0.0009938 | -0.0183834 | 0.9484071 | 0.9839938 | 0.7369075 | 1.0000000 | 1.0000000 | 1 |
| A1L0T0 | 0.0520381 | -0.0328378 | -0.0500166 | 0.4220779 | 0.5887446 | 0.5259740 | 0.9749035 | 1.0000000 | 1 |
| A3KMH1 | 0.4342224 | 0.3206653 | 0.5484563 | 0.1168831 | 0.2770563 | 0.0800866 | 0.9744878 | 0.9978006 | 1 |
| A4D1E9 | -0.0219254 | -0.0731552 | -0.0426655 | 0.6515152 | 0.1428571 | 0.2662338 | 0.9749035 | 0.9978006 | 1 |
The Reproducibility-Optimized Test Statistic (ROTS) (Elo et al.) introduces two additional parameters into the denominator of the classical t-test statistic, which it uses to maximize the overlap of top X differentially abundant proteins detected in bootstrap data sets, and hence also maximize the confidence of findings.
dat.dea$ROTS <- rots_test(dat.norm.summ.w2, sample.info, referenceCondition, otherConditions)
For each condition, we now get fold change estimates, p-values and q-values (adjusted p-values): see head of dataframe below.
display_dataframe_head(dat.dea$ROTS)
| logFC_0.125 | logFC_0.667 | logFC_1 | t.mod_0.125 | t.mod_0.667 | t.mod_1 | p.mod_0.125 | p.mod_0.667 | p.mod_1 | q.mod_0.125 | q.mod_0.667 | q.mod_1 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| A0AVT1 | -0.0296332 | -0.0190075 | 0.0086228 | 0.0432651 | 0.6287328 | -0.0281468 | 0.4657678 | 0.4094595 | 0.7445867 | 0.8145382 | 0.8649969 | 0.8806595 |
| A0FGR8 | 0.0121287 | 0.0389655 | 0.0247813 | -0.0175126 | -1.0684886 | -0.0792342 | 0.6911294 | 0.1963551 | 0.5225639 | 0.8677545 | 0.8154446 | 0.8537731 |
| A0MZ66 | 0.0035130 | -0.0009938 | -0.0183834 | -0.0049373 | 0.0155091 | 0.0550291 | 0.8322220 | 0.8752458 | 0.6194571 | 0.8819602 | 0.8861643 | 0.8715106 |
| A1L0T0 | 0.0520381 | -0.0328378 | -0.0500166 | -0.0717654 | 0.4836778 | 0.1390824 | 0.3112688 | 0.5051461 | 0.3468240 | 0.8007283 | 0.8664733 | 0.8369326 |
| A3KMH1 | 0.4342224 | 0.3206653 | 0.5484563 | -0.4752265 | -1.1284588 | -0.9781106 | 0.0071661 | 0.1760225 | 0.0044362 | 0.4461838 | 0.8102775 | 0.3413148 |
| A4D1E9 | -0.0219254 | -0.0731552 | -0.0426655 | 0.0310869 | 1.3375056 | 0.1350370 | 0.5607446 | 0.1193468 | 0.3561250 | 0.8344605 | 0.7335991 | 0.8400107 |
Now, the most important part: let’s find out how our component variants have affected the outcome of the DEA.
A confusion matrix shows how many true and false positives/negatives each variant has given rise to. Spiked proteins that are DE are true positives, background proteins that are not DE are true negatives. We calculate this matrix for all conditions and then calculate some other informative metrics based on the confusion matrices: accuracy, sensitivity, specificity, positive predictive value and negative predictive value.
Clearly, across the board, the non-parametric methods underperform while the moderated t-test gives rise to an acceptable but not spectacular sensitivity. That said, the contrast between conditions 0.667 and 0.5 seems not large enough to yield many significant results.
cm <- conf_mat(dat.dea, 'q.mod', 0.05, spiked.proteins)
print_conf_mat(cm, referenceCondition)
| background | spiked | background | spiked | background | spiked | background | spiked | |
|---|---|---|---|---|---|---|---|---|
| not_DE | 4061 | 4 | 4064 | 19 | 4064 | 19 | 4064 | 15 |
| DE | 3 | 15 | 0 | 0 | 0 | 0 | 0 | 4 |
| moderated_ttest | Wilcoxon | permutation_test | ROTS | |
|---|---|---|---|---|
| Accuracy | 0.998 | 0.995 | 0.995 | 0.996 |
| Sensitivity | 0.789 | 0.000 | 0.000 | 0.211 |
| Specificity | 0.999 | 1.000 | 1.000 | 1.000 |
| PPV | 0.833 | NaN | NaN | 1.000 |
| NPV | 0.999 | 0.995 | 0.995 | 0.996 |
| background | spiked | background | spiked | background | spiked | background | spiked | |
|---|---|---|---|---|---|---|---|---|
| not_DE | 4064 | 18 | 4064 | 19 | 4064 | 19 | 4064 | 19 |
| DE | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| moderated_ttest | Wilcoxon | permutation_test | ROTS | |
|---|---|---|---|---|
| Accuracy | 0.996 | 0.995 | 0.995 | 0.995 |
| Sensitivity | 0.053 | 0.000 | 0.000 | 0.000 |
| Specificity | 1.000 | 1.000 | 1.000 | 1.000 |
| PPV | 1.000 | NaN | NaN | NaN |
| NPV | 0.996 | 0.995 | 0.995 | 0.995 |
| background | spiked | background | spiked | background | spiked | background | spiked | |
|---|---|---|---|---|---|---|---|---|
| not_DE | 4060 | 5 | 4064 | 19 | 4064 | 19 | 4064 | 19 |
| DE | 4 | 14 | 0 | 0 | 0 | 0 | 0 | 0 |
| moderated_ttest | Wilcoxon | permutation_test | ROTS | |
|---|---|---|---|---|
| Accuracy | 0.998 | 0.995 | 0.995 | 0.995 |
| Sensitivity | 0.737 | 0.000 | 0.000 | 0.000 |
| Specificity | 0.999 | 1.000 | 1.000 | 1.000 |
| PPV | 0.778 | NaN | NaN | NaN |
| NPV | 0.999 | 0.995 | 0.995 | 0.995 |
To see whether the three Summarization methods produce similar results on the detailed level of individual proteins, we make scatter plots and check the correlation between their fold changes and between their significance estimates (q-values, in our case).
For all conditions, the q-values of the different variants correlate moderately well at best, though the Wilcoxon and permutation test correlate well (\(>0.921\)). ROTS seems consistently (over-)optimistic (i.e., low q-values, even for background proteins) even compared to the moderated t-test.
scatterplot_ils(dat.dea, significance.cols, 'q-values', spiked.proteins, referenceCondition)
On the other hand, the fold changes are very well correlated for all component variants, across all conditions, though the Wilcoxon estimates to a slightly lesser extent.
scatterplot_ils(dat.dea, logFC.cols, 'log2FC', spiked.proteins, referenceCondition)
The volcano plot combines information on fold changes and statistical significance. The spike-in proteins are colored blue, and immediately it is clear that their fold changes dominate the region of statistical significance, which suggests the experiment and analysis were carried out successfully. The magenta, dashed line indicates the theoretical fold change of the spike-ins.
for (i in 1:n.contrasts){
volcanoplot_ils(dat.dea, i, spiked.proteins, referenceCondition)}
A good way to assess the general trend of the fold change estimates on a more ‘macroscopic’ scale is to make a violin plot. Ideally, there will be some spike-in proteins that attain the expected fold change (red dashed line) that corresponds to their condition, while most (background) protein log2 fold changes are situated around zero.
@Piotr: results missing: add all violin plots first
# plot theoretical value (horizontal lines) and violin per variant
violinplot_ils(lapply(dat.dea[c('moderated_ttest', 'Wilcoxon')], function(x) x[spiked.proteins, logFC.cols]), referenceCondition)
It seems that the nonparametric methods do not have enough statistical power, even though ROTS is (over-)optimistic, producing low q-values for many background proteins, even compared to the moderated t-test. Though the correlation between their significance estimates is a bit all over the place, all variants do agree on the fold change estimates.
sessionInfo()
## R version 4.0.3 (2020-10-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.5 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=de_BE.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=de_BE.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=de_BE.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=de_BE.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats4 parallel stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ROTS_1.18.0 coin_1.4-0 survival_3.2-7 matrixTests_0.1.9 forcats_0.5.0 stringr_1.4.0 dplyr_1.0.2
## [8] purrr_0.3.4 readr_1.4.0 tidyr_1.1.2 tibble_3.0.4 ggplot2_3.3.2 tidyverse_1.3.0 psych_2.0.9
## [15] limma_3.45.19 kableExtra_1.3.1 dendextend_1.14.0 gridExtra_2.3 stringi_1.5.3 rmarkdown_2.5 pacman_0.5.1
##
## loaded via a namespace (and not attached):
## [1] readxl_1.3.1 backports_1.1.10 plyr_1.8.6 splines_4.0.3 BiocParallel_1.23.3
## [6] TH.data_1.0-10 digest_0.6.27 foreach_1.5.1 htmltools_0.5.0 viridis_0.5.1
## [11] fansi_0.4.1 magrittr_1.5 doParallel_1.0.16 recipes_0.1.14 modelr_0.1.8
## [16] gower_0.2.2 matrixStats_0.57.0 R.utils_2.10.1 sandwich_3.0-0 colorspace_1.4-1
## [21] signal_0.7-6 blob_1.2.1 rvest_0.3.6 haven_2.3.1 xfun_0.18
## [26] libcoin_1.0-7 crayon_1.3.4 jsonlite_1.7.1 impute_1.63.0 zoo_1.8-8
## [31] iterators_1.0.13 glue_1.4.2 gtable_0.3.0 ipred_0.9-9 zlibbioc_1.35.0
## [36] webshot_0.5.2 BiocGenerics_0.35.4 scales_1.1.1 mvtnorm_1.1-1 vsn_3.57.0
## [41] DBI_1.1.0 Rcpp_1.0.5 viridisLite_0.3.0 tmvnsim_1.0-2 preprocessCore_1.51.0
## [46] lava_1.6.8 prodlim_2019.11.13 httr_1.4.2 modeltools_0.2-23 ellipsis_0.3.1
## [51] pkgconfig_2.0.3 XML_3.99-0.5 R.methodsS3_1.8.1 farver_2.0.3 nnet_7.3-14
## [56] dbplyr_1.4.4 utf8_1.1.4 caret_6.0-86 tidyselect_1.1.0 labeling_0.4.2
## [61] rlang_0.4.8 reshape2_1.4.4 munsell_0.5.0 cellranger_1.1.0 tools_4.0.3
## [66] cli_2.1.0 generics_0.0.2 broom_0.7.2 evaluate_0.14 mzID_1.27.0
## [71] yaml_2.2.1 ModelMetrics_1.2.2.2 knitr_1.30 fs_1.5.0 packrat_0.5.0
## [76] ncdf4_1.17 nlme_3.1-150 R.oo_1.24.0 xml2_1.3.2 compiler_4.0.3
## [81] rstudioapi_0.11 png_0.1-7 e1071_1.7-4 affyio_1.59.0 reprex_0.3.0
## [86] highr_0.8 lattice_0.20-41 ProtGenerics_1.21.0 Matrix_1.2-18 vctrs_0.3.4
## [91] pillar_1.4.6 lifecycle_0.2.0 BiocManager_1.30.10 MALDIquant_1.19.3 data.table_1.13.2
## [96] R6_2.4.1 pcaMethods_1.81.0 affy_1.67.1 IRanges_2.23.10 codetools_0.2-16
## [101] MASS_7.3-53 assertthat_0.2.1 withr_2.3.0 mnormt_2.0.2 multcomp_1.4-15
## [106] S4Vectors_0.27.14 mgcv_1.8-33 hms_0.5.3 grid_4.0.3 rpart_4.1-15
## [111] timeDate_3043.102 class_7.3-17 pROC_1.16.2 Biobase_2.49.1 lubridate_1.7.9